/* Class BottomMessagePanel
 * 
 * 
 * 
 */
package disasterGameProj;


import java.awt.BorderLayout;
import java.awt.Color;
import java.awt.Dimension;
import java.awt.Graphics;
import java.awt.GridBagConstraints;
import java.awt.GridBagLayout;
import java.awt.Image;
import java.awt.Insets;

import javax.swing.JComponent;
import javax.swing.JLabel;
import javax.swing.JPanel;
import javax.swing.JScrollPane;
import javax.swing.JTextArea;
import javax.swing.JLayeredPane;

public class BottomMessagePanel 
{
	// initialize variables
	public JLayeredPane layeredPane = null;
	public JLayeredPane topRightLayeredPane = null;
	
	public JPanel mainBottomPanel = null;
	public JPanel leftPanel = null;
	public JPanel middlePanel = null;
	public JPanel topRightPanel = null;
	public JPanel bottomRightPanel = null;
	
	public RightDisplayPanel emptyPanel = null;
	public RightDisplayPanel roadPanel = null;
	public RightDisplayPanel hospitalPanel = null;
	public RightDisplayPanel fireStationPanel = null;
	public RightDisplayPanel regBuildingPanel = null;
	public RightDisplayPanel helipadPanel = null;
	
	public JLabel currentDamageLabel = null;
	public JLabel currentPopulationLabel = null;
	public JLabel isDiseasedLabel = null;
	public JLabel isOnFireLabel = null;
	public JLabel isFortifiedLabel = null;
	public JLabel cursorPositionLabel = null;
	public JLabel timerLabel = null;
	public JLabel moneyLabel = null;
	public JLabel exitLabel = null;
	
	public Sprite spriteObj = null;
	
	public JScrollPane messageScrollPane = null;
	
	public JTextArea messageTextArea = null;
	
	
	BottomMessagePanel( Sprite sprite )
	{
		spriteObj = sprite;
		
		mainBottomPanel = new JPanel();
		mainBottomPanel.setBounds( 0, 720, 1200, 212 );
		mainBottomPanel.setBackground( Color.BLACK );
		
		layeredPane = new JLayeredPane();
		
		createLeftPanel();
		createMiddlePanel();
		createTopRightPanel();
		createBottomRightPanel();
		
		layeredPane.setPreferredSize( new Dimension( 1200, 212 ) );
		layeredPane.setBounds(0, 0, 1200, 212 );
		layeredPane.add( leftPanel, new Integer( 1 ) );
		layeredPane.add( middlePanel, new Integer( 2 ) );
		layeredPane.add( topRightPanel, new Integer( 3 ) );
		layeredPane.add( bottomRightPanel, new Integer( 4 ) );
		
		mainBottomPanel.add( layeredPane );
		
	}



	private void createLeftPanel()
	{
		GridBagLayout gridbag = new GridBagLayout();
		GridBagConstraints gbc = new GridBagConstraints();
		
		leftPanel = new JPanel();
		leftPanel.setLayout( gridbag );
		leftPanel.setBounds( 0, 0, 300, 212 );
		leftPanel.setBackground( Color.yellow );
		
		currentDamageLabel = new JLabel( "Current Damage: " );
		currentDamageLabel.setPreferredSize( new Dimension( 200, 25 ) );
		currentPopulationLabel = new JLabel( "Current Population: ");
		currentPopulationLabel.setPreferredSize( new Dimension( 200, 25 ) );
		isDiseasedLabel = new JLabel( "Building Diseased: " );
		isDiseasedLabel.setPreferredSize( new Dimension( 200, 25 ) );
		isOnFireLabel = new JLabel( "Building on fire: " );
		isOnFireLabel.setPreferredSize( new Dimension( 200, 25 ) );
		isFortifiedLabel = new JLabel( "Building Fortified: " );
		isFortifiedLabel.setPreferredSize( new Dimension( 200, 25 ) );
		cursorPositionLabel = new JLabel( "Cursor position: [ ]:[ ]" );
		cursorPositionLabel.setPreferredSize( new Dimension( 200, 25 ) );
		
		
		gbc.gridx = 0;
		gbc.gridy = 0;
		gbc.weighty = 1;
		gbc.fill = GridBagConstraints.HORIZONTAL;
		gbc.insets = new Insets( 0, 0, 0, 100 );
		gridbag.setConstraints( currentDamageLabel, gbc );
		leftPanel.add( currentDamageLabel );
		
		gbc.gridy = 1;
		gridbag.setConstraints( currentPopulationLabel, gbc );
		leftPanel.add( currentPopulationLabel );
		
		gbc.gridy = 2;
		gridbag.setConstraints( isFortifiedLabel, gbc );
		leftPanel.add( isFortifiedLabel );
		
		gbc.gridy = 3;
		gridbag.setConstraints( isOnFireLabel, gbc );
		leftPanel.add( isOnFireLabel );
		
		gbc.gridy = 4;
		gridbag.setConstraints( isDiseasedLabel, gbc );
		leftPanel.add( isDiseasedLabel );
		
		gbc.insets = new Insets( 35, 0, 0, 100 );
		gbc.gridy = 5;
		gridbag.setConstraints( cursorPositionLabel, gbc );
		leftPanel.add( cursorPositionLabel );
		
	}
	
	private void createMiddlePanel()
	{
		middlePanel = new JPanel();
		middlePanel.setBounds( 300, 0, 500, 212 );
		middlePanel.setBackground( Color.CYAN );
		
		messageTextArea = new JTextArea();
		messageTextArea.setEditable( false );
		messageScrollPane = new JScrollPane( messageTextArea );
		
		messageScrollPane.setPreferredSize( new Dimension( 490, 200 ) );
		messageScrollPane.setBounds(5, 0, 450, 212 );
		
		middlePanel.add( messageScrollPane );
		 
	}

	private void createTopRightPanel() 
	{
		topRightLayeredPane = new JLayeredPane();
		
		topRightPanel = new JPanel();
		topRightPanel.setBounds( 800, 0, 400, 162 );
		topRightPanel.setBackground( Color.red );
		
		emptyPanel = new RightDisplayPanel( spriteObj.emptyPurchase );
		roadPanel = new RightDisplayPanel( spriteObj.roadPurchase );
		hospitalPanel = new RightDisplayPanel( spriteObj.hospitalPurchase );
		fireStationPanel = new RightDisplayPanel( spriteObj.fireStationPurchase );
		regBuildingPanel = new RightDisplayPanel( spriteObj.regBuildingPurchase );
		helipadPanel = new RightDisplayPanel( spriteObj.helipadPurchase );
		
		topRightLayeredPane.setLayout( null );
		topRightLayeredPane.setPreferredSize( new Dimension( 400, 162 ) );
		topRightLayeredPane.setBounds(0, 0, 400, 162 );
		
		topRightLayeredPane.add( emptyPanel, new Integer( 1 ) );
		topRightLayeredPane.add( roadPanel, new Integer( 2 ) );
		topRightLayeredPane.add( hospitalPanel, new Integer( 3 ) );
		topRightLayeredPane.add( helipadPanel, new Integer( 4 ) );
		topRightLayeredPane.add( regBuildingPanel, new Integer( 5 ) );
		topRightLayeredPane.add( fireStationPanel, new Integer( 6 ) );
		
		topRightPanel.add( topRightLayeredPane );
	}
	
	private void createBottomRightPanel()
	{
		GridBagLayout gridbag = new GridBagLayout();
		GridBagConstraints gbc = new GridBagConstraints();
		
		bottomRightPanel = new JPanel();
		bottomRightPanel.setBounds( 800, 162, 400, 50 );
		bottomRightPanel.setBackground( Color.ORANGE );
		bottomRightPanel.setLayout( gridbag );
		
		timerLabel = new JLabel( "10:00" );
		timerLabel.setPreferredSize( new Dimension( 100, 25 ) );
		moneyLabel = new JLabel();
		moneyLabel.setPreferredSize( new Dimension( 100, 25 ) );
		exitLabel = new JLabel( "Exit" );
		exitLabel.setPreferredSize( new Dimension( 100, 25 ) );
		
		gbc.gridx = 0;
		gbc.gridy = 0;
		gbc.weightx = 1;
		gbc.fill = GridBagConstraints.HORIZONTAL;
		gbc.insets = new Insets( 0, 20, 0, 0 );
		gridbag.setConstraints( timerLabel, gbc );
		bottomRightPanel.add( timerLabel );

		gbc.gridx = 1;
		gbc.insets = new Insets( 0, 60, 0, 0 );
		gridbag.setConstraints( moneyLabel, gbc );
		bottomRightPanel.add( moneyLabel );
		
		gbc.gridx = 2;
		gbc.insets = new Insets( 0, 100, 0, 0 );
		gridbag.setConstraints( exitLabel, gbc );
		bottomRightPanel.add( exitLabel );
		
	}
	
	public class RightDisplayPanel extends JComponent
	{
		Image myImage = null;
		
		RightDisplayPanel( Image image )
		{
			myImage = image;
			setPreferredSize( new Dimension( 400, 162 ) );
			setBounds( 0, 0, 400, 162 );
			setVisible( false );
		}
		
		public void paint(Graphics g) 
	    {	
			g.drawImage( myImage, 0, 0, null );
	    }
	}
}
